package com.sky.controller.user;

import com.sky.constant.MessageConstant;
import com.sky.constant.RedisDataBaseNameConstant;
import com.sky.exception.ShopStatusException;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "店铺相关接口")
@RestController(value = "UserShopController")
@RequestMapping("/user/shop")
public class ShopController {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    /**
     * 用户端获取店铺状态
     * @return 店铺状态，1为营业，0为关闭
     */
    @ApiOperation("获取店铺状态")
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        Integer status = (Integer) redisTemplate.opsForValue().get(RedisDataBaseNameConstant.SHOP_STATUS_KEY);
        if(status == null){
            throw new ShopStatusException(MessageConstant.SHOP_STATUS_EXCEPTION);
        }
        log.info("获取店铺状态：{}", status == 1?"营业":"关闭");
        return Result.success(status);
    }
}
